<?php
	function f402($sql){
		//data handle instance
		//set request
		//define format
		//set format
		//define query string
		//process time
		//process fitler
		$dataHandle = new DataHandle();
		$dataHandle->setRequest("402");

		$dataType = getValue($_GET['dataType']);

		if($dataType == "json"){
			$format = array(
				"Date" => "datem/d/Y g:i:s A",
				);
			$dataHandle->setFormat($format);
			
			$query = getLinesQuery();
			print($dataHandle->printJSON($sql, $query));
		}
		else{
			$temp = array();
			$temp['error'] = "402: Bad request";
			print(json_encode($temp));
		}

		unset($dataHandle);
	}

	function getLinesQuery(){
		$queryString = "
			SELECT
				sys_OnLine_Data_Statuses.name as Name, 
				CASE 
					WHEN sys_OnLine_Data_Statuses.value = 0 THEN 'OFF' 
					WHEN sys_OnLine_Data_Statuses.value = 1 THEN 'RUN' 
					WHEN sys_OnLine_Data_Statuses.value = 2 THEN 'PAUSE' 
				ELSE '?' END AS Status,
				sys_OnLine_Data_Recipes.value as Value, 
				sys_OnLine_Data_Statuses.date as Date
			FROM sys_OnLine_Data_Statuses inner join sys_OnLine_Data_Recipes
				on sys_OnLine_Data_Statuses.name = sys_OnLine_Data_Recipes.name

			where sys_OnLine_Data_Statuses.name like 'Line%'";
		return $queryString;
	}

?>